// pages/work/list.js
var app = getApp();
Page({
  data:{
    workOrderList:[],
    loginImg:'',
    loginName:'',
    aliasName:'',
    color:'#aaaaaa',
    statusList:[],
    slaList:[]
  },
  onLoad:function(options){
    var that = this;
    // 页面初始化 options为页面跳转所带来的参数
    that.setData({
      loginImg:wx.getStorageSync('loginInfo').image.absoluteImagePath,
      loginName:wx.getStorageSync('loginInfo').user.loginName,
      aliasName:wx.getStorageSync('loginInfo').user.aliasName
    })
    // 状态分类
    wx.request({
      url: app.globalData.API + '/workOrder/countEngineerStatus',
      data: {
        id:wx.getStorageSync('loginInfo').user.id
      },
      method: 'POST', 
      header: {
        "Cookie":wx.getStorageSync('sessionid')
      },
      success: function(res){
        // success
        if(res.data.code == 10000){
          var engineerStatusVo = res.data.obj.engineerStatusVo;
          for(let i=0;i<engineerStatusVo.length;i++){
            if(engineerStatusVo[i].status == '未接单'){
              var weijiedan = engineerStatusVo[i].num;
              continue;
            }
            if(engineerStatusVo[i].status == '未上门'){
              var weishangmen = engineerStatusVo[i].num;
              continue;
            }
            if(engineerStatusVo[i].status == '维修中'){
              var weixiuzhong = engineerStatusVo[i].num;
              continue;
            }
            if(engineerStatusVo[i].status == '已完成'){
              var yiwancheng = engineerStatusVo[i].num;
              continue;
            }
          }
          var sList = [
            {
              url:'',
              num:weijiedan == undefined ? 0 :weijiedan,
              status:'未接单',
            },
            {
              url:'',
              num:weishangmen == undefined ? 0 :weishangmen,
              status:'未上门',
            },
            {
              url:'',
              num:weixiuzhong == undefined ? 0 :weixiuzhong,
              status:'维修中',
            },
            {
              url:'',
              num:yiwancheng == undefined ? 0 :yiwancheng,
              status:'已完成',
            }
          ];
          for(let i=0;i<sList.length;i++){
            sList[i].color = '#aaaaaa';
            if(sList[i].num != '0'){
              sList[i].color = '#f57e00';
            }
          }
          that.setData({
            statusList:sList
          })
        }
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    });
    // SLA分类
    wx.request({
      url: app.globalData.API + '/sla/appSla',
      data: {
        engineerId:wx.getStorageSync('loginInfo').user.id
      },
      method: 'POST', 
      header: {
        "Cookie":wx.getStorageSync('sessionid')
      },
      success: function(res){
        // success
        if(res.data.code == 10000){
          var slaContent = res.data.lists.content;
          for(let i=0;i<slaContent.length;i++){
            slaContent[i].color = '#aaaaaa';
            if(slaContent[i].count != '0'){
              slaContent[i].color = '#f57e00';
            }
          }
          that.setData({
            slaList:slaContent
          })
        }
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    });
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },  
  onPullDownRefresh: function(){//下拉刷新
    var that = this;
    that.setData({
      loginImg:wx.getStorageSync('loginInfo').image.absoluteImagePath,
      loginName:wx.getStorageSync('loginInfo').user.loginName,
      aliasName:wx.getStorageSync('loginInfo').user.aliasName
    })
    // 状态分类
    wx.request({
      url: app.globalData.API + '/workOrder/countEngineerStatus',
      data: {
        id:wx.getStorageSync('loginInfo').user.id
      },
      method: 'POST', 
      header: {
        "Cookie":wx.getStorageSync('sessionid')
      },
      success: function(res){
        // success
        if(res.data.code == 10000){
          var engineerStatusVo = res.data.obj.engineerStatusVo;
          for(let i=0;i<engineerStatusVo.length;i++){
            if(engineerStatusVo[i].status == '未接单'){
              var weijiedan = engineerStatusVo[i].num;
              continue;
            }
            if(engineerStatusVo[i].status == '未上门'){
              var weishangmen = engineerStatusVo[i].num;
              continue;
            }
            if(engineerStatusVo[i].status == '维修中'){
              var weixiuzhong = engineerStatusVo[i].num;
              continue;
            }
            if(engineerStatusVo[i].status == '已完成'){
              var yiwancheng = engineerStatusVo[i].num;
              continue;
            }
          }
          var sList = [
            {
              url:'',
              num:weijiedan == undefined ? 0 :weijiedan,
              status:'未接单',
            },
            {
              url:'',
              num:weishangmen == undefined ? 0 :weishangmen,
              status:'未上门',
            },
            {
              url:'',
              num:weixiuzhong == undefined ? 0 :weixiuzhong,
              status:'维修中',
            },
            {
              url:'',
              num:yiwancheng == undefined ? 0 :yiwancheng,
              status:'已完成',
            }
          ];
          for(let i=0;i<sList.length;i++){
            sList[i].color = '#aaaaaa';
            if(sList[i].num != '0'){
              sList[i].color = '#f57e00';
            }
          }
          that.setData({
            statusList:sList
          })
        }
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    });
    // SLA分类
    wx.request({
      url: app.globalData.API + '/sla/appSla',
      data: {
        engineerId:wx.getStorageSync('loginInfo').user.id
      },
      method: 'POST', 
      header: {
        "Cookie":wx.getStorageSync('sessionid')
      },
      success: function(res){
        // success
        if(res.data.code == 10000){
          var slaContent = res.data.lists.content;
          for(let i=0;i<slaContent.length;i++){
            slaContent[i].color = '#aaaaaa';
            if(slaContent[i].count != '0'){
              slaContent[i].color = '#f57e00';
            }
          }
          that.setData({
            slaList:slaContent
          })
        }
      },
      fail: function(res) {
        // fail
      },
      complete: function(res) {
        // complete
      }
    });
    setTimeout(function(){
            //停止刷新
            wx.stopPullDownRefresh()
          },2000)
  }
})